<?php 

$host_db = "ArquitectosDB.db.10377925.hostedresource.com";
$user_db = "ArquitectosDB";
$dbname = "ArquitectosDB";
$pass_db = "Prueba123!";

if (!isset($_FILES['imagen'])) {
			echo '<p>Seleccione una imagen por favor</p>';
		} else {
			try {

				//include "conexion.php";
				$maxsize = 5000000;
				//set to approx 5 MB

				//check associated error code
				if ($_FILES['imagen']['error'] == UPLOAD_ERR_OK) {

					//check whether file is uploaded with HTTP POST
					if (is_uploaded_file($_FILES['imagen']['tmp_name'])) {

						//checks size of uploaded image on server side
						if ($_FILES['imagen']['size'] < $maxsize) {
							//$finfo = finfo_open(FILEINFO_MIME_TYPE);
							//if(strpos(finfo_file($finfo, $_FILES['userfile']['tmp_name']),"image")===0) {
							if (true) {
								// prepare the image for insertion
								$imgData = addslashes(file_get_contents($_FILES['imagen']['tmp_name']));

								// put the image in the db...
								// database connection
								mysql_connect($host_db, $user_db, $pass_db) OR DIE(mysql_error());

								// select the db
								mysql_select_db($dbname) OR DIE("No se pudo realizar la conexión para guardar la imagen");

								// our sql query

								$sql = "update slider set imagen='{$imgData}' where id=5";

								//echo "<script language='JavaScript'>alert('$sql');</script>";										
								//('{$imgData}', '{$_FILES['userfile']['name']}');

								// insert the image
								mysql_query($sql) or die("Error in Query: " . mysql_error());

								header('Location: cambiarslider.php?msg=Se ha cambiado correctamente la imagen');

							} else
								header('Location: cambiarslider.php?msg=No se selecciono una imagen par guardar.');

						} else {
							// if the file is not less than the maximum allowed, print an error
							header('Location: cambiarslider.php?url=registraempresa.php&msg=La imagen pasa el limite maximo<br>.
						El tamaño maximo de la imagen es ' . ($maxsize / 500000) . ' megabytes<br>
						El tamaño de la es ' . $_FILES['imagen']['name'] . ' is ' . ($_FILES['imagen']['size'] / 500000) . ' megabytes');

						}
					} else{
						header('Location: cambiarslider.php?msg=Su imagen no se ha podido subir. (1)');
						$msg = "File not uploaded successfully.";
					}
					

				} else {
					header('Location: cambiar.php?msg=Su imagen no se ha podido subir2. (2)');

				}
				//this will upload your image
			} catch(Exception $e) {
				header('Location: cambiarslider.php?msg=Su imagen no se ha podido subir3. (3)');
			}
		}
 ?>